<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="1200"  @ok="handleSubmit" okText="放行">
    <a-card title="放行信息" :bordered="false" class="mt-5">
      <a-descriptions :column="3">
        <a-descriptions-item label="姓名"> {{rowObj.wbname}} </a-descriptions-item>
        <a-descriptions-item label="证件类型"> {{rowObj.wbpaperType_dictText}} </a-descriptions-item>
        <a-descriptions-item label="证件号码"> {{rowObj.wbpaperNumber}} </a-descriptions-item>
        <a-descriptions-item label="手机号码"> {{rowObj.wbphone}} </a-descriptions-item>
        <a-descriptions-item label="来访人数"> {{rowObj.wbcount}} </a-descriptions-item>
        <a-descriptions-item label="车牌号"> {{rowObj.wbplate}} </a-descriptions-item>
        <a-descriptions-item label="预约来访时间"> {{rowObj.willVisitTime}} </a-descriptions-item>
        <a-descriptions-item label="预约截止时间"> {{rowObj.willVisitEndTime}} </a-descriptions-item>
        <a-descriptions-item label="预约途径"> {{rowObj.source_dictText}} </a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card title="受访人信息" :bordered="false" class="mt-5">
      <a-descriptions :column="3">
        <a-descriptions-item label="受访人姓名"> {{rowObj.personName}} </a-descriptions-item>
        <a-descriptions-item label="受访人学/工号"> {{rowObj.personCode}} </a-descriptions-item>
        <a-descriptions-item label="受访人所属部门"> {{rowObj.personDept}} </a-descriptions-item>
       <!-- <a-descriptions-item label="受访人人员类型"> {{rowObj.personType_dictText}} </a-descriptions-item>-->
        <a-descriptions-item label="来访说明"> {{rowObj.visitDescription}} </a-descriptions-item>
        <a-descriptions-item label="是否允许"> {{rowObj.allow_dictText}} </a-descriptions-item>
        <a-descriptions-item label="审批备注"> {{rowObj.remark}} </a-descriptions-item>

      </a-descriptions>
    </a-card>
    <a-card title="门信息" :bordered="false" class="mt-5">
      <a-descriptions :column="3">
        <a-descriptions-item label="门位置"> {{ch.gateName}} </a-descriptions-item>
        <a-descriptions-item label="设备"> {{ch.deviceName}} </a-descriptions-item>

      </a-descriptions>
    </a-card>
    <BasicForm @register="registerForm" v-show="false"/>
  </BasicModal>
</template>

<script lang="ts" setup>
  import {ref, computed, unref, reactive} from 'vue';
  import {BasicModal, useModalInner} from '/@/components/Modal';
  import {BasicForm, useForm} from '/@/components/Form/index';
  import {formSchema} from '/@/views/visitor/appointment/SsVisitAppointment.data';
  import {saveOrUpdate}  from '/@/views/visitor/appointment/SsVisitAppointment.api';
  import {checkVisitor} from "@/views/visitor/record/SsVisitRecord.api";
  // Emits声明
  const emit = defineEmits(['register','success']);
  const isUpdate = ref(true);
  //表单配置
  const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({
    labelWidth: 150,
    schemas: formSchema,
    showActionButtonGroup: false,
    baseColProps: {span: 12},
  });
  const update1 = reactive({update:{}});
  const rowObj = ref({});
  const ch = ref({});
  //表单赋值
  const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
    //重置表单
    await resetFields();
    setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
    isUpdate.value = !!data?.isUpdate;
    rowObj.value = data.record;
    //ch.value.channelId = data.channelId;
    ch.value.gateName = data.gateName;
    ch.value.deviceId = data.deviceId;
    ch.value.deviceName = data.deviceName;
    console.log(data.record)

    if (unref(isUpdate)) {
      //表单赋值
      await setFieldsValue({
        ...data.record,
      });
    }
    update1.update = data.update;
    // 隐藏底部时禁用整个表单
    setProps({ disabled: true })
  });
  //设置标题
  const title = "访客放行";//computed(() => (!unref(isUpdate) ? '新增' : ''));
  //表单提交事件
  async function handleSubmit(v) {
    try {
      let values = await validate();
      setModalProps({confirmLoading: true});
      //提交表单
      let params = {};
      params.id = values.id;
      params.type = "ap";
      params.deviceId = ch.deviceId;
    let res = await checkVisitor(params);
      update1.update();
      //关闭弹窗
      closeModal();
      //刷新列表
      emit('success');
    } finally {
      setModalProps({confirmLoading: false});
    }
  }
</script>

<style lang="less" scoped>
  /** 时间和数字输入框样式 */
  :deep(.ant-input-number){
    width: 100%
  }

  :deep(.ant-calendar-picker){
    width: 100%
  }
</style>
